package com.kl.rabbitmqprovider.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Solution {
    public static ArrayList<String> merge(ArrayList<String> input) {
        ArrayList<String> result = new ArrayList<>();
        String s = input.toString();
        s = s.substring(1, s.length() - 1);
        // 特殊情况
        if (s.contains("0.0.0.0-255.255.255.255")) {
            result.add("0.0.0.0-255.255.255.255");
            return result;
        }
        String[] splits = s.split(", ");
        Arrays.sort(splits, Comparator.comparingInt(String::length).thenComparing(o -> o));
        for (String split : splits) {
            System.out.println(split);
        }
        return result;
    }

    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("192.168.0.1");
        list.add("192.168.0.12-192.168.0.15");
        list.add("192.168.0.2");
        list.add("192.168.0.7-192.168.0.9");
        list.add("192.168.0.11");
        list.add("192.168.0.3-192.168.0.5");
        list.add("192.168.0.16");
        list.add("192.168.0.100");
        merge(list);
    }
}